<template>
	<view class="mystudent">
		<view class="title">
			<u-icon name="arrow-left" size="24" @click="back"></u-icon>
			<text style="margin-left: 24rpx;">我的学生</text>
		</view>
		<view class="" style="height: 176rpx"></view>

		<view class="datalist">
			<view class="boxitem" v-for="(item,index) in studentData" :key="index">
				<view class="top">
					<view class="timetext">
						申报时间：{{item.student.create_time}}
					</view>
					<view v-if="item.status==0" class="status" style="color: #C90000;">待确认</view>
					<view v-if="item.status==1" class="status" style="color: #FE532D;">已同意</view>
					<view v-if="item.status==2" class="status" style="color: #FE532D;">已拒绝</view>
					<view v-if="item.status==3" class="status" style="color: #999999;">已过期</view>
					<view v-if="item.status==4" class="status" style="color: #999999;">已调换</view>
				</view>
				<view class="bottom">
					<view class="itemleft">
						<view class="avaterbox">
							<image class="avatartimg" :src="item.student.photos.url"></image>
						</view>
						<view class="nameandmessage">
							<view class="name">
								{{item.student.name}}
							</view>
							<view class="message">
								{{item.student.school}}/{{item.student.speciality}}
							</view>
						</view>
					</view>

					<view class="itemright">
						<view class="baokao">
							报考：
						</view>
						<view class="zhuanye">
							{{item.student.science_id_text}}
						</view>
					</view>
				</view>
				<!-- <view v-if="true" class="btnsbox"> -->
				<view v-if="item.status==0" class="btnsbox">
					<view class="reject btn" @click="handlereject(item.student.id)">
						拒绝
					</view>
					<view class="pass btn" @click="handlepassShow(item.student.id)">
						通过
					</view>
				</view>

			</view>
		</view>

		<u-popup :show="passshow" mode="center" :round="10">
			<view class="popcontent">
				<text class="text">确定要选择该学生吗，您当前还可选择1 人，选择后如需解绑请联系客服</text>
				<view class="btnbox">
					<view class="btn" @click="closepass">
						取消
					</view>
					<view class="btn btnok" @click="subokpass">
						确认
					</view>
				</view>
			</view>
		</u-popup>

		<u-popup :show="rejectshow" mode="center" :round="10">
			<view class="popcontent popcontents">
				<text class="text">确定要拒绝该学生吗</text>
				<view class="btnbox">
					<view class="btn" @click="rejectshow = false">
						取消
					</view>
					<view class="btn btnok" @click="rejectStudent">
						确认
					</view>
				</view>
			</view>
		</u-popup>

	</view>
</template>

<script>
	import {
		myStudent,
		passStudent,
		rejectStudent
	} from "@/api/api.js"
	export default {
		data() {
			return {
				passshow: false,
				rejectshow: false,
				studentData: [],
			}
		},
		onLoad(options) {
			console.log("options", options)
			this.myStudents()
		},
		methods: {
			async myStudents() {
				let res = await myStudent({
					page: 1,
					size: 10,
				})
				if (res.code == 1) {
					console.log("我的学生", res)
					this.studentData = res.data
				}
			},
			handlepassShow(id) {
				// this.passshow = true
				this.studentId = id
				let that = this
				uni.showModal({
					// title: '提示',
					content: '确定要选择该学生吗，您当前还可选择1 人，选择后如需解绑请联系客服？',
					confirmColor: '#4A9CFF',
					success: async function(res) {
						console.log("是否选择", res)
						if (res.confirm) {
							that.handlePass()
						}
					}
				})
			},
			closepass() {
				console.log("2222")
				this.passshow = false

			},

			async handlePass() {
				console.log("学生id", this.studentId)
				let res = await passStudent({
					student_id: this.studentId
				})
				if (res.code == 1) {
					uni.showToast({
						title: '已通过该学生！',
						icon: 'none',
						duration: 1000
					})
					this.passshow = false
					this.myStudents()
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none',
						duration: 1000
					})
				}
			},
			handlereject(id) {
				// this.rejectshow = true
				this.studentId = id
				uni.showModal({
					// title: '提示',
					content: '确定要拒绝该生吗？',
					confirmColor: '#4A9CFF',
					success: async function(res) {
						console.log("是否选择", res)
						if (res.confirm) {
							that.rejectStudent()
						}
					}
				})
			},
			async rejectStudent() {
				console.log("学生id", this.studentId)
				let res = await rejectStudent({
					student_id: this.studentId
				})
				if (res.code == 1) {
					uni.showToast({
						title: '已拒绝该学生！',
						icon: 'none',
						duration: 1000
					})
					this.rejectshow = false
					this.myStudents()
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none',
						duration: 1000
					})
				}
			},

			back() {
				uni.navigateBack({
					delta: 1
				});
			}

		}
	}
</script>

<style scoped lang="scss">
	.popcontent {
		width: 610rpx;
		height: 240rpx;
		background: #FFFFFF;
		border-radius: 24rpx 24rpx 24rpx 24rpx;
		opacity: 1;
		padding-top: 50rpx;
		box-sizing: border-box;
		z-index: 999;

		.text {
			// width: 100%;
			height: 50rpx;
			font-size: 30rpx;
			font-family: PingFang SC-Bold, PingFang SC;
			font-weight: bold;
			color: #333333;
			line-height: 45rpx;
			padding: 0 40rpx;
			display: inline-block;
		}

		.btnbox {
			width: 100%;
			height: 100rpx;
			border-top: 1px solid gainsboro;
			box-sizing: border-box;
			margin-top: 70rpx;
			display: flex;

			.btn {
				width: 50%;
				text-align: center;
				line-height: 100rpx;
				font-size: 32rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #333333;
				line-height: 38rpx;
				padding-top: 30rpx;
				box-sizing: border-box;
			}

			.btnok {
				border-left: 1px solid gainsboro;
				color: #4A9CFF;
			}
		}

	}

	.popcontents {
		height: 203rpx;
	}

	.mystudent {
		min-height: 100%;
		background-color: #F7F8FA;


		.title {
			width: 100%;
			height: 176rpx;
			padding-top: 110rpx;
			box-sizing: border-box;
			background-color: #FFFFFF;
			display: flex;
			align-items: center;
			font-size: 32rpx;
			font-family: PingFang SC-Bold, PingFang SC;
			font-weight: bold;
			color: #333333;
			line-height: 38rpx;
			padding-left: 34rpx;
			box-sizing: border-box;
			position: fixed;
			top: 0;
			z-index: 99;
		}

		.datalist {
			padding: 30rpx;
			box-sizing: border-box;

			.boxitem {
				width: 690rpx;
				background: #FFFFFF;
				border-radius: 30rpx 30rpx 30rpx 30rpx;
				margin-bottom: 30rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				padding: 30rpx;
				box-sizing: border-box;

				.top {
					display: flex;
					justify-content: space-between;

					.timetext {
						font-size: 28rpx;
						font-family: PingFang SC-Bold, PingFang SC;
						font-weight: bold;
						color: #333333;
						line-height: 33rpx;

					}

					.status {
						font-size: 28rpx;
						font-family: PingFang SC-Bold, PingFang SC;
						font-weight: bold;
						color: #999999;
						line-height: 33rpx;
					}
				}

				.bottom {
					display: flex;
					justify-content: space-between;
					margin-top: 10rpx;

					.itemleft {
						display: flex;

						.avaterbox {
							.avatartimg {
								margin-right: 10rpx;
								width: 104rpx;
								height: 104rpx;
								border-radius: 100rpx;
							}
						}

						.nameandmessage {
							// padding-top: 5rpx;
							box-sizing: border-box;
							display: flex;
							flex-direction: column;
							justify-content: space-around;
							// align-items: center;

							.name {
								font-size: 32rpx;
								font-family: PingFang SC-Bold, PingFang SC;
								font-weight: bold;
								color: #333333;
								line-height: 38rpx;
							}

							.message {
								width: 360rpx;
								// background-color: pink;
								font-size: 26rpx;
								font-family: PingFang SC-Regular, PingFang SC;
								font-weight: 400;
								color: #666666;
								line-height: 30rpx;
								white-space: nowrap;
								overflow: hidden;
								text-overflow: ellipsis;
								// margin-top: 20rpx;
							}
						}

					}

					.itemright {
						display: flex;
						align-items: center;
						flex-direction: column;
						justify-content: space-around;
						text-align: left;

						.baokao {
							font-size: 26rpx;
							font-family: PingFang SC-Regular, PingFang SC;
							font-weight: 400;
							color: #666666;
							line-height: 30rpx;
						}

						.zhuanye {
							height: 48rpx;
							background: #F0F7FF;
							border-radius: 12rpx 12rpx 12rpx 12rpx;
							opacity: 1;
							border: 2rpx solid #4A9CFF;
							font-size: 24rpx;
							font-family: PingFang SC-Regular, PingFang SC;
							font-weight: 400;
							color: #4A9CFF;
							line-height: 28rpx;
							text-align: center;
							line-height: 48rpx;
							padding: 0 7rpx;

						}
					}
				}

				.btnsbox {
					width: 100%;
					height: 100rpx;
					// background-color: pink;
					display: flex;
					justify-content: space-between;
					margin-top: 36rpx;
					padding: 0 20rpx;
					box-sizing: border-box;

					.btn {
						width: 260rpx;
						height: 80rpx;
						border-radius: 200rpx 200rpx 200rpx 200rpx;
						opacity: 1;
						font-family: PingFang SC-Bold, PingFang SC;
						font-weight: bold;
						line-height: 35rpx;
						text-align: center;
						line-height: 80rpx;
					}

					.reject {
						border: 2rpx solid #C90000;
						font-size: 30rpx;
						color: #C90000;
					}

					.pass {
						background: #4A9CFF;
						color: #FFFFFF;
					}


				}
			}
		}
	}
</style>